﻿using UnityEngine;
using System.Collections;

public class TempFacebookUI : MonoBehaviour {
	public UILabel nameLabel;
	public UITexture pictureTex;
	// Use this for initialization
	void Start () {
#if !UNITY_EDITOR
		if(FB.IsLoggedIn)
		{
			if( gameObject.name.Contains("Name") )
				FB.API("/me", Facebook.HttpMethod.GET, GetMyProfileCallback);			
			else if( gameObject.name.Contains("Pic") )
				StartCoroutine(FBUtil.GetPictureTexture(FB.UserId, 128, 128, null, true, GetMyThumnailCallback));	
		}
		else
		{
			nameLabel.gameObject.SetActive(false);
			pictureTex.gameObject.SetActive(false);
		}
#endif
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	
	void GetMyProfileCallback(FBResult result)
	{
		nameLabel.text = FBUtil.DeserializeJSONProfile(result.Text)["first_name"].ToString();
	}
	
	void GetMyThumnailCallback(Texture tex)
	{
		Debug.LogError("GetMyThumnailCallback");
		pictureTex.mainTexture = tex;
	}
}
